package com.taoxi.good.controller;

import com.taoxi.common.annotation.Log;
import com.taoxi.common.core.controller.BaseController;
import com.taoxi.common.core.domain.AjaxResult;
import com.taoxi.common.core.page.TableDataInfo;
import com.taoxi.common.enums.BusinessType;
import com.taoxi.common.utils.poi.ExcelUtil;
import com.taoxi.good.domain.Good;
import com.taoxi.good.service.IGoodService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 商品展示Controller
 *
 * @author ruoyi
 * @date 2024-10-21
 */
@Api(tags = "商品展示Controller")
@RestController
@RequestMapping("/good/good")
public class GoodController extends BaseController {
    @Autowired
    private IGoodService goodService;

    /**
     * 查询商品展示列表
     */
    @ApiOperation("查询商品展示列表")
    @PreAuthorize("@ss.hasPermi('good:good:list')")
    @GetMapping("/list")
    public TableDataInfo list(Good good) {
        startPage();
        List<Good> list = goodService.selectGoodList(good);
        return getDataTable(list);
    }

    /**
     * 导出商品展示列表
     */
    @ApiOperation("导出商品展示列表")
    @PreAuthorize("@ss.hasPermi('good:good:export')")
    @Log(title = "商品展示", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Good good) {
        List<Good> list = goodService.selectGoodList(good);
        ExcelUtil<Good> util = new ExcelUtil<Good>(Good.class);
        util.exportExcel(response, list, "商品展示数据");
    }

    /**
     * 获取商品展示详细信息
     */
    @ApiOperation("获取商品展示详细信息")
    @PreAuthorize("@ss.hasPermi('good:good:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(goodService.selectGoodById(id));
    }

    /**
     * 新增商品展示
     */
    @ApiOperation("新增商品展示")
    @PreAuthorize("@ss.hasPermi('good:good:add')")
    @Log(title = "商品展示", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Good good) {
        return toAjax(goodService.insertGood(good));
    }

    /**
     * 修改商品展示
     */
    @ApiOperation("修改商品展示")
    @PreAuthorize("@ss.hasPermi('good:good:edit')")
    @Log(title = "商品展示", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Good good) {
        return toAjax(goodService.updateGood(good));
    }

    /**
     * 删除商品展示
     */
    @ApiOperation("删除商品展示")
    @PreAuthorize("@ss.hasPermi('good:good:remove')")
    @Log(title = "商品展示", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(goodService.deleteGoodByIds(ids));
    }
}
